package net.wanho.service.impl;

import net.wanho.constant.EmpConstant;
import net.wanho.dao.EmpDao;
import net.wanho.dao.impl.EmpDaoImpl;
import net.wanho.entity.Emp;
import net.wanho.exception.EmpExistsException;
import net.wanho.service.EmpService;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-07-30 9:27
 * Description：<描述>
 */
public class EmpServiceImpl implements EmpService {

    private EmpDao empDao = new EmpDaoImpl();

    @Override
    public void add(Emp emp) {
        /**
         * 判断名称是否存在
         */
        Emp e = empDao.selectByName(emp.getName());
        if(e != null){
            throw new EmpExistsException("员工已存在");
        }

        // 设置状态默认为启用
        emp.setStatus(EmpConstant.STATUS_ENABLE);

        empDao.insert(emp);
    }

    @Override
    public List<Emp> findAll() {
        return empDao.selectAll();
    }
}
